package net.entelijan.cobean.bind.impl;

import java.beans.PropertyChangeListener;
import java.util.List;

import net.entelijan.cobean.core.impl.AbstractComponentBean;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class BoundPropertyBean extends AbstractComponentBean {

    private static Log log = LogFactory.getLog(BoundPropertyBean.class);

    private String bound;
    private List<RowBeanX> boundList;

    public BoundPropertyBean(String bound, List<RowBeanX> boundList) {
        super();
        this.bound = bound;
        this.boundList = boundList;
    }

    public String getBound() {
        return bound;
    }

    public void setBound(String bound) {
        log.debug("[setBound] " + bound);
        String oldBound = this.bound;
        this.bound = bound;
        propertyChangeSupport.firePropertyChange("bound", oldBound, bound);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }

    public List<RowBeanX> getBoundList() {
        return boundList;
    }

    public void setBoundList(List<RowBeanX> boundList) {
        log.debug("[setBoundList] " + boundList);
        List<RowBeanX> oldBoundList = this.boundList;
        this.boundList = boundList;
        propertyChangeSupport.firePropertyChange("boundList", oldBoundList, this.boundList);
    }

    public void setBoundList(int index, RowBeanX row) {
        log.debug("[setBoundList] " + boundList);
        RowBeanX oldValue = this.boundList.get(index);
        this.boundList.set(index, row);
        propertyChangeSupport.fireIndexedPropertyChange("boundList", index, oldValue, row);
    }

    public RowBeanX getBoundList(int index) {
        return this.boundList.get(index);
    }

}
